﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getAllTeams : FunctionBase
    {
        private MarsExplorerEntities dbContext;

        public getAllTeams(HttpContext context)
            : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            List<Team> allTeams = dbContext.Teams.ToList();
            StringBuilder sb = new StringBuilder();

            foreach (Team i in allTeams.AsEnumerable())
            {
                sb.Append(i.TeamID + ",");
                sb.Append(i.Name + ",");
                sb.Append(i.Route.Name + ",");
                sb.Append(i.Minerals + ",");
                sb.Append(i.Credits + ";");
            }
            return sb.ToString();
        }

        public override void InitializeProperties()
        {
            try
            {
                dbContext = new MarsExplorerEntities();
            }
            catch (Exception e)
            {
                string message = "";
#if DEBUG
                message += " : " + e.ToString();

#endif

               
            }
        }
    }
}